package com.devilvan.betrice.po;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.devilvan.betrice.common.BasePo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serial;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
* @author Evad.Wu
* @Description 目录/菜单/按钮信息表 映射
* @date 2023-08-11
*/
@Setter
@Getter
@ToString(exclude = {"sysRolePoSet"})
@EqualsAndHashCode(callSuper = false, exclude = {"sysRolePoSet"})
@NoArgsConstructor
@Accessors(chain = true)
@TableName(value = "SYS_MENU")

@Entity
@Table(name = "SYS_MENU")
@DynamicInsert
@EntityListeners(AuditingEntityListener.class)
@Schema(description = "目录/菜单/按钮信息表 映射")
public class SysMenuPo extends BasePo implements Serializable {
    @Serial
    private static final long serialVersionUID = -1147129186425810209L;
    @Schema(description = "菜单名称")
    @TableField(value = "MENU_NAME")
    @Column(name = "MENU_NAME", columnDefinition = "VARCHAR(50) NOT NULL COMMENT '菜单名称'")
    private String menuName;
    @Schema(description = "父菜单ID")
    @TableField(value = "PARENT_ID")
    @Column(name = "PARENT_ID", columnDefinition = "BIGINT(19) COMMENT '父菜单ID'")
    private Long parentId;
    @Schema(description = "显示顺序")
    @TableField(value = "ORDER_NUM")
    @Column(name = "ORDER_NUM", columnDefinition = "INT(10) COMMENT '显示顺序'")
    private Integer orderNum;
    @Schema(description = "路由地址")
    @TableField(value = "PATH")
    @Column(name = "PATH", columnDefinition = "VARCHAR(200) COMMENT '路由地址'")
    private String path;
    @Schema(description = "组件路径")
    @TableField(value = "COMPONENT")
    @Column(name = "COMPONENT", columnDefinition = "VARCHAR(255) COMMENT '组件路径'")
    private String component;
    @Schema(description = "路由参数")
    @TableField(value = "QUERY_PARAM")
    @Column(name = "QUERY_PARAM", columnDefinition = "VARCHAR(255) COMMENT '路由参数'")
    private String queryParam;
    @Schema(description = "是否为外链（Y-是 N-否）")
    @TableField(value = "IS_FRAME")
    @Column(name = "IS_FRAME", columnDefinition = "CHAR(1) COMMENT '是否为外链（Y-是 N-否）'")
    private String isFrame;
    @Schema(description = "是否缓存（Y-缓存 N-不缓存）")
    @TableField(value = "IS_CACHE")
    @Column(name = "IS_CACHE", columnDefinition = "CHAR(1) COMMENT '是否缓存（Y-缓存 N-不缓存）'")
    private String isCache;
    @Schema(description = "菜单类型（见MENU_TYPE）")
    @TableField(value = "MENU_TYPE")
    @Column(name = "MENU_TYPE", columnDefinition = "CHAR(1) COMMENT '菜单类型（见MENU_TYPE）'")
    private String menuType;
    @Schema(description = "显示状态（0显示 1隐藏）")
    @TableField(value = "VISIBLE")
    @Column(name = "VISIBLE", columnDefinition = "CHAR(1) COMMENT '显示状态（0显示 1隐藏）'")
    private String visible;
    @Schema(description = "菜单状态（0正常 1停用）")
    @TableField(value = "STATUS")
    @Column(name = "STATUS", columnDefinition = "CHAR(1) COMMENT '菜单状态（0正常 1停用）'")
    private String status;
    @Schema(description = "权限标识")
    @TableField(value = "PERMS")
    @Column(name = "PERMS", columnDefinition = "VARCHAR(100) COMMENT '权限标识'")
    private String perms;
    @Schema(description = "菜单图标")
    @TableField(value = "ICON")
    @Column(name = "ICON", columnDefinition = "VARCHAR(100) COMMENT '菜单图标'")
    private String icon;

    @Schema(description = "菜单对应的角色")
    @TableField(exist = false)
    @ManyToMany(targetEntity = SysRolePo.class, cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
    @JoinTable(name = "SYS_ROLE_MENU",
            joinColumns = {@JoinColumn(name = "MENU_ID", referencedColumnName = "ID")},
            inverseJoinColumns = {@JoinColumn(name = "ROLE_ID", referencedColumnName = "ID")})
    @Fetch(value = FetchMode.SUBSELECT)
    @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    private Set<SysRolePo> sysRolePoSet = new HashSet<>(0);
}
